package com.rbcs.budget.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.rbcs.flow.FlowConstants;
import com.rbcs.flow.model.Flow;
import com.systop.common.modules.dept.model.Dept;
import com.systop.common.modules.security.user.model.User;
import com.systop.core.model.BaseModel;

/**
 * 部门预算表
 * 
 * @author Nice
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "budgets")
public class Budget extends BaseModel {

	private Integer id;

	// 预算编号
	private String singleNo;

	private Double amount;

	private User creater;

	private Dept dept;

	private Integer year;

	private List<BudgetItem> budgetItems = new ArrayList<BudgetItem>(0);

	private Date createTime;

	// 周期类型[月度、季度]
	private String btype;

	// 审批流程
	private List<Flow> flows = new ArrayList<Flow>(0);

	// 审核状态[未审核,待审,审核通过,审核未通过]
	private String audStatus = FlowConstants.AUDIT_UNSEND;

	@Id
	@GeneratedValue(generator = "hibseq")
	@GenericGenerator(name = "hibseq", strategy = "hilo")
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "single_no")
	public String getSingleNo() {
		return singleNo;
	}

	public void setSingleNo(String singleNo) {
		this.singleNo = singleNo;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "create_id")
	public User getCreater() {
		return creater;
	}

	public void setCreater(User creater) {
		this.creater = creater;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "dept_id")
	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "budget")
	@OrderBy("item")
	public List<BudgetItem> getBudgetItems() {
		return budgetItems;
	}

	public void setBudgetItems(List<BudgetItem> budgetItems) {
		this.budgetItems = budgetItems;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "btype")
	public String getBtype() {
		return btype;
	}

	public void setBtype(String btype) {
		this.btype = btype;
	}

	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "budget")
	public List<Flow> getFlows() {
		return flows;
	}

	public void setFlows(List<Flow> flows) {
		this.flows = flows;
	}

	@Column(name = "aud_status")
	public String getAudStatus() {
		return audStatus;
	}

	public void setAudStatus(String audStatus) {
		this.audStatus = audStatus;
	}

	@Transient
	public Flow getTopFlow() {
		return (flows.isEmpty()) ? null : flows.get(0);
	}

}
